/**
 * zbestpayment.com Inc.
 * Copyright (c) 2004-2017 All Rights Reserved.
 */
package com.zbest.zpay.gw.assemble;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.zbest.common.lang.util.MessageCastor;
import com.zbest.zpay.gw.cache.MessageTemplateCache;
import com.zbest.zpay.gw.dal.model.GwMessageTemplateDO;
import com.zbest.zpay.gw.model.MessageContext;
import com.zbest.zpay.gw.model.MessageType;

/**
 * 
 *
 * @author Administrator
 * @version $Id: DefaultMessageAssemble.java, v 0.1 2017-4-11 下午11:43:38 Administrator Exp $
 */
@Service("defaultMessageAssemble")
public class DefaultMessageAssemble implements MessageAssemble {

    @Resource
    private MessageCastor        messageCastor;

    @Resource
    private MessageTemplateCache messageTemplateCache;

    /** 
     * @see com.zbest.zpay.gw.assemble.MessageAssemble#buildRequest(com.zbest.zpay.gw.model.MessageContext)
     */
    @Override
    public void buildRequest(MessageContext messageContext) {

        GwMessageTemplateDO gwMessageTemplateDO = messageTemplateCache.get(messageContext
            .getChannelId());
        if (StringUtils.equals(gwMessageTemplateDO.getMessageType(), MessageType.TEXT.name())) {
            String message = messageCastor.cast(messageContext.getRequestData(),
                gwMessageTemplateDO.getAssembleTemplate());

            messageContext.setSendMessage(message);
            //messageContext.getResponseData().put(GwKeyEnum.MESSAGE_CONTENT.getCode(), message);
        }

    }

}
